package com.esisa.dao.hibernate;

import java.util.List;

import org.hibernate.Query;

import com.esisa.dao.TypeBetailDao;
import com.esisa.models.TypeBetail;

public class TypeBetailDaoHibernate extends AbstractHibernateDao implements TypeBetailDao{

	@Override
	public boolean insert(TypeBetail typeBetail) {
		beginTransaction();
			TypeBetail t=(TypeBetail) session.get(TypeBetail.class,typeBetail.getType());
			if(t!=null)
			 return false;
			session.save(typeBetail);
		commit();
		return true;
	}

	@Override
	public TypeBetail select(String type) {
		beginTransaction();
		TypeBetail typeBetail=(TypeBetail) session.get(TypeBetail.class,type);
		commit();
		return typeBetail;
	}

	@Override
	public void delete(TypeBetail typeBetail) {
		beginTransaction();
			session.delete(typeBetail);
		commit();
	}

	@Override
	public void update(TypeBetail typeBetail) {
		beginTransaction();
			session.save(typeBetail);
		commit();
	}

	@Override
	public List<TypeBetail> selectAll() {
		List<TypeBetail>res=null;
		beginTransaction();
			Query query = session.createQuery("SELECT t FROM TypeBetail t");
			 res= query.list();
		commit();
		return res;
	}
	
	
}
